package cn.chinaunicom.admin.utils;

import cn.chinaunicom.admin.entity.AppServer;

/**
 * @ProjectName: esay-secret-server
 * @Package: cn.chinaunicom.admin.utils
 * @ClassName: AppContentHandler
 * @Description: java类作用描述
 * @Author: wangjc
 * @CreateDate: 2023/11/24
 * @UpdateUser: wangjc
 * @UpdateDate: 2023/11/24
 * @UpdateRemark: 更新内容
 * @Version: 1.0
 */
public class AppContextHandler {
    private ThreadLocal<AppServer> threadLocal;
    private static AppContextHandler instance = new AppContextHandler();

    private AppContextHandler(){
        threadLocal = new ThreadLocal<>();
    }

    public static AppContextHandler getInstance(){
        return instance;
    }

    public AppServer getApp(){
        return this.threadLocal.get();
    }

    public void setApp(AppServer app){
        this.threadLocal.set(app);
    }

    /**
     * 清空上下文
     */
    public void clear() {
        threadLocal.remove();
    }
}
